package 第一章基础算法.高精度.id793高精度乘法;

import java.util.Scanner;

/**
 * 方法一：直接竖式乘法，边运算边进位
 * 方法二：help数组保存中间结果，运算完后最后进位，更简便
 */
public class Main {
    public static void main(String[] args) {
        //处理输入
        Scanner scanner = new Scanner(System.in);
        String num1 = scanner.next();
        String num2 = scanner.next();
        //求积
        String res = decimalMul(num1,num2);
        //处理输出
        System.out.println(res);
    }

    public static String decimalMul(String num1, String num2){
        int n = num1.length();
        int m = num2.length();
        //保存乘积中间结果
        int[] c = new int[m+n];
        for(int i=n-1;i>=0;i--){
            for(int j = m-1;j>=0;j--){
                c[(n-1)+(m-1)-i-j] += (num1.charAt(i)-'0') * (num2.charAt(j)-'0');
            }
        }
        //遍历c[]求结果
        int carry = 0;
        StringBuilder sb = new StringBuilder();
        for(int i = 0;i<m+n;i++){
            int temp = carry + c[i];
            carry = temp / 10;
            sb.append(temp%10);
        }
        //如果有进位
        if(carry >0)sb.append(carry);
        //去除前导0
        int cur = sb.length()-1;
        while(cur > 0 && sb.charAt(cur) == '0'){
            sb.deleteCharAt(cur);
            cur--;
        }
        return sb.reverse().toString();
    }
}

